package com.huike.controller.index;

import com.huike.vo.BacklogVo;
import com.huike.vo.BasicDataVo;
import com.huike.result.Result;
import com.huike.service.IndexService;
import com.huike.vo.SalesFunnelVo;
import com.huike.vo.TopSalesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController

@RequestMapping("/index")
public class IndexController {
    @Autowired
    private IndexService indexService;

    /**
     * 基础数据展示
     *
     * @return
     */
    @GetMapping("/basicData")
    public Result basicData(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                            @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        // 查询数据
        BasicDataVo basicDataVo = indexService.basicData(beginTime, endTime);

        return Result.success(basicDataVo);
    }

    /**
     * 今日简报
     *
     * @return
     */
    @GetMapping("/todayBulletin")
    public Result todayBulletin() {
        BasicDataVo basicDataVo = indexService.todayBulletin();
        return Result.success(basicDataVo);
    }

    /**
     * 代办事项
     *
     * @return
     */
    @GetMapping("/backlog")
    public Result backlog(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                          @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        BacklogVo backlogVo = indexService.backlog(beginTime, endTime);
        return Result.success(backlogVo);
    }


    /**
     * 销售漏斗
     *
     * @return
     */
    @GetMapping("/salesFunnel")
    public Result salesFunnel(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                              @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        SalesFunnelVo salesFunnelVo = indexService.salesFunnel(beginTime, endTime);
        return Result.success(salesFunnelVo);
    }


    /**
     * 销售排行
     *
     * @return
     */
    @GetMapping("/topSales")
    public Result topSales(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        TopSalesVo topSalesVo = indexService.topSales(beginTime,endTime);
        return Result.success(topSalesVo);
    }

}
